package com.mkb.controller;

import com.github.pagehelper.PageInfo;
import com.mkb.common.BaseController;
import com.mkb.common.ModuleURL;
import com.mkb.common.URL;
import com.mkb.conf.NotDuplicateRequest;
import com.mkb.entity.AreaDTO;
import com.mkb.entity.GraphDTO;
import com.mkb.entity.UserInfoDTO;
import com.mkb.enums.GraphEnum;
import com.mkb.service.AreaService;
import com.mkb.service.GraphService;
import com.zz.common.result.ResultInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Controller
@RequestMapping(ModuleURL.GRAPHATTR)
public class GraphAttrController extends BaseController {
	@Autowired
    private GraphService graphService;
	@Autowired
    private AreaService areaService;

    @RequestMapping(value = "/color", method = RequestMethod.GET)
    public ModelAndView color(Model model, Long graphId) throws Exception{
        return new ModelAndView("page/graphattr/color");
    }

    @RequestMapping(value = URL.OP_CREATE, method = RequestMethod.GET)
    public ModelAndView createPage(Model model, Long graphId) throws Exception{
        GraphDTO graphDTO = graphService.getAttr(graphId);
        List<AreaDTO> areaList = areaService.queryList(AreaDTO.builder().build());
        model.addAttribute("graph", graphDTO);
        model.addAttribute("areaList", areaList);
        return new ModelAndView("page/graphattr/create");
    }

    @RequestMapping(value = URL.OP_CREATE, method = RequestMethod.POST)
    @ResponseBody
    @NotDuplicateRequest
    public ResultInfo create(Model model, @RequestBody GraphDTO graphDTO) throws Exception{
        graphService.updateAttr(graphDTO);
        return ResultInfo.ok();
    }

}
